<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\User
 *
 * @property integer $id
 * @property string $username
 * @property string $email
 * @property string $phone
 * @property string $password
 * @property string $reg_ip
 * @property string $reg_time
 * @property string $login_ip
 * @property string $login_time
 * @property integer $login_count
 * @property integer $role
 * @property integer $status
 * @property string $remember_token
 * @property string $deleted_at
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @method static \Illuminate\Database\Query\Builder|\App\User whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereUsername($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereEmail($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User wherePhone($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User wherePassword($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereRegIp($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereRegTime($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereLoginIp($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereLoginTime($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereLoginCount($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereRole($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereStatus($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereRememberToken($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereDeletedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\User whereUpdatedAt($value)
 * @property-read \App\Facilitator $facilitator
 */
class User extends Model implements AuthenticatableContract{

    use Authenticatable;

	//表名
    protected $table = "users" ;
    protected $hidden = ['password','remember_token'];
    use SoftDeletes;

    public function facilitator(){
        return $this->hasOne('App\Facilitator','user_id');
    }

    public function getDisplayName()
    {
        if ($this->facilitator && $this->facilitator->nickname) {
            return $this->facilitator->nickname;
        } else if ($this->username)
            return $this->username;
        else if ($this->email)
            return $this->email;
        else if ($this->phone)
            return $this->phone;
        return $this->id;
    }

}
